package cn.buk.tms.entity.order.flight;

import cn.buk.tms.entity.base.BaseOrderInfo;

import jakarta.persistence.*;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

/**
 * 机票改签订单
 *
 * @author yfdai
 */
@Entity
@Table(name = "flt_change_order",
        uniqueConstraints = @UniqueConstraint(
                name = "uk_flt_change_order",
                columnNames = {"enterprise_id", "balance_code", "ticket_no", "change_count"}))
@AssociationOverride(name = "customer",
        joinColumns = @JoinColumn(name = "customer_id"),
        foreignKey = @ForeignKey(name = "fk_flt_change_customer")
)
@AssociationOverride(name = "supplier",
        joinColumns = @JoinColumn(name = "supplier_id"),
        foreignKey = @ForeignKey(name = "fk_flt_change_supplier")
)
@AssociationOverride(name = "paymentMethod",
        joinColumns = @JoinColumn(name = "payment_method_id"),
        foreignKey = @ForeignKey(name = "fk_flt_change_payment_method")
)
public class FlightChangeOrder extends BaseOrderInfo {
  /**
   * 0 - 提交改签，等待处理
   * 1 - 我来处理
   * 2 - 改签完成，回填新编码和票号（如果有)
   * 4 - 已取消
   */
  public static final int ORDER_STATUS_WAITING = 0;
  public static final int ORDER_STATUS_WORKING = 1;
  public static final int ORDER_STATUS_FINISHED = 2;
  public static final int ORDER_STATUS_CANCELED = 4;

  @Column(name = "balance_code", length = 3)
  private String balanceCode;

  /**
   * 改签的机票的票号
   */
  @Column(name = "ticket_no", length = 10)
  private String ticketNo;

  /**
   * 该票的改签次数
   * 有些票号改签后不会产生新票号，再次改签时就会用原票号改签
   */
  @Column(name = "change_count")
  private Integer changeCount;

  /**
   * 改签单单号
   */
  @Column(name = "change_order_no", length = 10)
  private String changeOrderNo;

  /**
   * CZ NDC外部改签单号
   */
  @Column(name = "external_order_no", length = 20)
  private String externalOrderNo;

  /**
   * 对应的机票订单的订单号
   * 订单号(该改签单来自哪个机票订单）
   */
  @Column(name = "order_no", length = 10)
  private String orderNo;

  /**
   * 对应的机票订单的id
   */
  @Column(name = "order_id")
  private Integer orderId;

  @Column(name = "parent_change_order_no", length = 10)
  private String parentChangeOrderNo;

  /**
   * 旅客姓名
   */
  @Column(name = "psg_name", length = 50)
  private String psgName;

  @Column(name = "id_no", length = 20)
  private String idNo;

  /**
   * 联系电话, 乘机人的联系电话，和机票订单中乘机人的联系电话相同
   */
  @Column(length = 20)
  private String mobile;


  private Double parvalue;

  private Double tax;


  /**
   * 企业收的改签服务费
   */
  @Column(name = "service_charge")
  private double serviceCharge;

  /**
   * 航司收的改签费
   */
  @Column(name = "air_change_fee")
  private double airChangeCharge;

  /**
   * 0 - 提交改签，等待处理
   * 1 - 我来处理
   * 2 - 改签完成，回填新编码和票号（如果有)
   */
  private int status;

  /**
   * 2 - 已销账
   */
  @Column(name = "pay_status")
  private Integer payStatus;

  /**
   * 改签类型
   * 0-升舱
   * 1-更改
   * 2-签转
   */
  @Column(name = "change_type")
  private int changeType;


  /**
   * 原编码(如果有）
   */
  @Column(name = "old_pnr", length = 8)
  private String oldPnrNo;

  /**
   * 新编码(如果有）
   */
  @Column(name = "new_pnr", length = 8)
  private String newPnrNo;

  /**
   * 原来的大编码，用于航司的B2B
   */
  @Column(name = "old_big_pnr", length = 10)
  private String oldBigPnr;

  /**
   * 新的大编码，用于航司的B2B
   */
  @Column(name = "new_big_pnr", length = 10)
  private String newBigPnr;

  /**
   * 新票号(如果有）
   */
  @Column(name = "new_ticket_no", length = 14)
  private String newTicketNo;

  private String remark;

  @OneToMany(mappedBy = "order", cascade = {CascadeType.ALL}, fetch = FetchType.EAGER)
  @OrderBy("flight.departureDate, flight.departureTime")
  private Set<FlightChangeOrderDetail> flights;

  /**
   * 是否国际票改签
   * 0-否
   * 1-是
   */
  @Column(name = "intl_ticket")
  private int intlTicket;


  /**
   * 联系人（代订人）从机票订单中来，冗余数据
   */
  @Column(length = 20)
  private String linkman;

  /**
   * 联系人（代订人）从机票订单中来，冗余数据
   */
  @Column(length = 20, name = "link_phone")
  private String linkPhone;

  /**
   * PNR详情刷新状态
   * 1: 出票完成后已重新获取了pnr详情
   * 4: 获取失败
   */
  @Column(name = "pnr_refresh_status")
  private Integer pnrRefreshStatus;

  /**
   * DETR刷新状态
   * 1 - 已刷新
   * 2 - 已更新到FlightOrderTicket中
   * 4 - 找不到，应该是获取不到DETR信息，非授权OFFICE开票
   * 8 - 票号状态已到终态，无需再检查
   */
  @Column(name = "detr_refresh_status")
  private Integer detrRefreshStatus;


  @Temporal(TemporalType.TIMESTAMP)
  @Column(name = "detr_refresh_time")
  private Date detrRefreshTime;

  public String getRemark() {
    return remark;
  }

  public void setRemark(String remark) {
    this.remark = remark;
  }

  public int getStatus() {
    return status;
  }

  public void setStatus(int status) {
    this.status = status;
  }


  public String getTicketNo() {
    return ticketNo;
  }

  public void setTicketNo(String ticketNo) {
    this.ticketNo = ticketNo;
  }

  public String getPsgName() {
    return psgName;
  }

  public void setPsgName(String psgName) {
    this.psgName = psgName;
  }

  public String getBalanceCode() {
    return balanceCode;
  }

  public void setBalanceCode(String balanceCode) {
    this.balanceCode = balanceCode;
  }

  public double getServiceCharge() {
    return serviceCharge;
  }

  public void setServiceCharge(double serviceCharge) {
    this.serviceCharge = serviceCharge;
  }

  public String getOrderNo() {
    return orderNo;
  }

  public void setOrderNo(String orderNo) {
    this.orderNo = orderNo;
  }

  public int getOrderId() {
    return orderId == null ? 0 : orderId;
  }

  public void setOrderId(Integer orderId) {
    this.orderId = orderId;
  }

  public String getIdNo() {
    return idNo;
  }

  public void setIdNo(String idNo) {
    this.idNo = idNo;
  }

  public double getParvalue() {
    return parvalue == null ? 0 : parvalue;
  }

  public void setParvalue(double parvalue) {
    this.parvalue = parvalue;
  }

  public double getTax() {
    return tax == null ? 0 : tax;
  }

  public void setTax(double tax) {
    this.tax = tax;
  }

  public String getChangeOrderNo() {
    return changeOrderNo;
  }

  public void setChangeOrderNo(String changeOrderNo) {
    this.changeOrderNo = changeOrderNo;
  }

  public double getAirChangeCharge() {
    return airChangeCharge;
  }

  public void setAirChangeCharge(double airChangeCharge) {
    this.airChangeCharge = airChangeCharge;
  }

  public Set<FlightChangeOrderDetail> getFlights() {
    if (flights == null) {
      this.flights = new HashSet<>();
    }
    return flights;
  }

  public void setFlights(Set<FlightChangeOrderDetail> flights) {
    this.flights = flights;
  }

  public int getIntlTicket() {
    return intlTicket;
  }

  public void setIntlTicket(int intlTicket) {
    this.intlTicket = intlTicket;
  }

  public int getChangeType() {
    return changeType;
  }

  public void setChangeType(int changeType) {
    this.changeType = changeType;
  }

  public String getNewPnrNo() {
    return newPnrNo;
  }

  public void setNewPnrNo(String newPnrNo) {
    this.newPnrNo = newPnrNo;
  }

  public String getNewTicketNo() {
    return newTicketNo == null ? "" : newTicketNo.trim();
  }

  public void setNewTicketNo(String newTicketNo) {
    this.newTicketNo = newTicketNo;
  }

  public String getOldPnrNo() {
    return oldPnrNo;
  }

  public void setOldPnrNo(String oldPnrNo) {
    this.oldPnrNo = oldPnrNo;
  }

  public String getLinkman() {
    return linkman;
  }

  public void setLinkman(String linkman) {
    this.linkman = linkman;
  }

  public String getLinkPhone() {
    return linkPhone;
  }

  public void setLinkPhone(String linkPhone) {
    this.linkPhone = linkPhone;
  }


  public String getParentChangeOrderNo() {
    return parentChangeOrderNo;
  }

  public void setParentChangeOrderNo(String parentChangeOrderNo) {
    this.parentChangeOrderNo = parentChangeOrderNo;
  }

  public int getPayStatus() {
    return payStatus == null ? 0 : payStatus;
  }

  public void setPayStatus(Integer payStatus) {
    this.payStatus = payStatus;
  }

  public int getChangeCount() {
    return changeCount == null ? 0 : changeCount;
  }

  public void setChangeCount(Integer changeCount) {
    this.changeCount = changeCount;
  }

  public String getMobile() {
    return mobile;
  }

  public void setMobile(String mobile) {
    this.mobile = mobile;
  }

  public Integer getPnrRefreshStatus() {
    return pnrRefreshStatus;
  }

  public void setPnrRefreshStatus(Integer pnrRefreshStatus) {
    this.pnrRefreshStatus = pnrRefreshStatus;
  }

  public Integer getDetrRefreshStatus() {
    return detrRefreshStatus;
  }

  public void setDetrRefreshStatus(Integer detrRefreshStatus) {
    this.detrRefreshStatus = detrRefreshStatus;
  }

  public Date getDetrRefreshTime() {
    return detrRefreshTime;
  }

  public void setDetrRefreshTime(Date detrRefreshTime) {
    this.detrRefreshTime = detrRefreshTime;
  }

  public String getExternalOrderNo() {
    return externalOrderNo;
  }

  public void setExternalOrderNo(String externalOrderNo) {
    this.externalOrderNo = externalOrderNo;
  }

  public String getOldBigPnr() {
    return oldBigPnr;
  }

  public void setOldBigPnr(String oldBigPnr) {
    this.oldBigPnr = oldBigPnr;
  }

  public String getNewBigPnr() {
    return newBigPnr;
  }

  public void setNewBigPnr(String newBigPnr) {
    this.newBigPnr = newBigPnr;
  }
}
